package mx.netbrain.business;

import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import mx.netbrain.dao.UserDao;
import mx.netbrain.model.User;
import mx.netbrain.util.NetBrainUtils;

import org.apache.log4j.Logger;

public class LoginBusiness {

	private static final Logger logger = Logger.getLogger(LoginBusiness.class);
	private static UserDao userDao = new UserDao();
	private static List<User> userList = new ArrayList<User>();

	public static User ValidaLogin(String username, String password)
			throws NoSuchAlgorithmException {
		User user = new User();
		userList = userDao
				.findByUsername(username, NetBrainUtils.md5(password));
		if (userList.size() > 0) {
			for (User userFor : userList) {
				user = userFor;
			}
		} else {
			user = null;
			logger.warn("El objeto user regreso null.");
		}
		return user;
	}

}
